package 锁.lock.fairLock;

import java.util.concurrent.CountDownLatch;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/9/5 16:39
 * @description:
 * @version:
 */
public class Test {
    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            Runnable runnable = () -> {
                System.out.println(Thread.currentThread().getName() + "线程开始执行");
                latch.countDown();
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "线程睡眠结束");
            };
            Thread thread = new Thread(runnable);
            thread.setName("线程" + i);
            thread.start();
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            System.out.println("超时");
        }
    }
}
